﻿'Changes to this test branch!

Public Class frmConfig

    Public Property ServerURL As String
    Public Property UserName As String
    Public Property Password As String
    Public Property ReportPath As String
    Public Property Timeout As Integer
    Public Property dictReports As Generic.Dictionary(Of String, String)

    Public Sub New(ByVal _ServerURL As String, ByVal _UserName As String, ByVal _Password As String, ByVal _ReportPath As String, ByVal _Timeout As Integer, ByVal _dictReports As Generic.Dictionary(Of String, String))

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        ServerURL = _ServerURL
        UserName = _UserName
        Password = _Password
        ReportPath = _ReportPath
        'report path must begin and end with slashes
        If Not ReportPath.StartsWith("/") Then ReportPath = "/" & ReportPath
        If Not ReportPath.EndsWith("/") Then ReportPath &= "/"
        Timeout = _Timeout
        dictReports = _dictReports
    End Sub

    Private Sub chkWindowsSecurity_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkWindowsSecurity.CheckedChanged
        ResetWindowsSecurity()
    End Sub

    Private Sub ResetWindowsSecurity()
        If chkWindowsSecurity.Checked Then
            txtUserName.Text = ""
            txtPassword.Text = ""
            lblUserName.Visible = False
            txtUserName.Visible = False
            lblPassword.Visible = False
            txtPassword.Visible = False
        Else
            lblUserName.Visible = True
            txtUserName.Visible = True
            lblPassword.Visible = True
            txtPassword.Visible = True
        End If
    End Sub

    Private Sub frmConfig_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        txtServer.Text = _ServerURL
        If _UserName = "" Then
            chkWindowsSecurity.Checked = True
        Else
            chkWindowsSecurity.Checked = False
            txtUserName.Text = _UserName
            txtPassword.Text = _Password
        End If
        txtPath.Text = _ReportPath
        txtTimeout.Text = Timeout
        With dgReports
            .Columns.Add("Report Description", "Report Description")
            .Columns.Add("Report Name on Server", "Report Name on Server")
            .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
            .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
            .AllowUserToAddRows = True
            .AllowUserToDeleteRows = True
            .AllowUserToOrderColumns = False
            .AllowUserToResizeColumns = False
            .AllowUserToResizeRows = False
            For Each s As String In _dictReports.Keys
                .Rows.Add(s, _dictReports(s))
            Next
        End With
    End Sub

    Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        ServerURL = txtServer.Text
        UserName = txtUserName.Text
        Password = txtPassword.Text
        ReportPath = txtPath.Text
        Timeout = Val(txtTimeout.Text)
        dictReports.Clear()
        With dgReports
            For r As Integer = 0 To .Rows.Count - 2
                Dim rptDesc As String = .Item(0, r).Value
                rptDesc = rptDesc.Replace(":", ";") 'necessary because : is delimiter in ini file
                Dim rptName As String = .Item(1, r).Value
                rptName = rptName.Replace(":", ";")
                If Not String.IsNullOrEmpty(rptDesc) AndAlso Not String.IsNullOrEmpty(rptName) AndAlso Not dictReports.ContainsKey(rptDesc) Then
                    dictReports.Add(rptDesc, rptName)
                End If
            Next
        End With
    End Sub

    Private Sub btnView_Click(sender As System.Object, e As System.EventArgs) Handles btnView.Click
        With New frmReporting(txtServer.Text, txtUserName.Text, txtPassword.Text, txtPath.Text, txtTimeout.Text, dgReports.Item(1, dgReports.CurrentCellAddress.Y).Value)
            .ShowDialog(Me)
        End With
    End Sub
End Class